import { SitesVO } from '@/api/communicateSettings/sites/types';
import { StationVO } from '@/api/communicateSettings/station/types';
import { GisEditorVO } from '@/api/dataCenter/gisEditor/types';
import { computeStationIcon, computeOverlayLabel, initSiteIcon } from './common';
import { convertStringToLatLng } from '@/utils/gis';

// 绘制polyline
export const initPolyline = (map: any, options: GisEditorVO) => {
  window.BM.polyline(options.path, {
    color: options.strokeColor,
    weight: options.strokeWeight
  }).addTo(map);
  // 绘制线名称
  window.BM.marker(convertStringToLatLng(options.center), {
    icon: window.BM.divIcon({ html: computeOverlayLabel(options), iconSize: null, className: '' })
    // opacity: 0
  }).addTo(map);
};

// 绘制polygon
export const initPolygon = (map: any, options: GisEditorVO) => {
  window.BM.polygon(options.path, {
    color: options.strokeColor,
    weight: options.strokeWeight,
    fillColor: options.fillColor,
    fillOpacity: options.fillOpacity
  }).addTo(map);
  // 绘制区域名称
  window.BM.marker(convertStringToLatLng(options.center), {
    icon: window.BM.divIcon({ html: computeOverlayLabel(options), iconSize: null, className: '' })
    // opacity: 0
  }).addTo(map);
};

// 创建测点图标
export const initStationIcon = (options: StationVO) => {
  const icon = window.BM.divIcon({ html: computeStationIcon(options), iconSize: null, className: '' });
  //   console.log(icon);
  return icon;
};

// 创建测点标记
export const initStationMarker = (layer: any, options: StationVO) => {
  const marker = window.BM.marker(convertStringToLatLng(options.stlalo), {
    icon: initStationIcon(options)
  }).addTo(layer);
  marker.stationProps = { stcd: options.stcd, alarmLevel: options.alarmLevel, zoom: options.mapLevel };
  return marker;
};

// 创建测站标记
export const initSiteMarker = (layer: any, options: SitesVO) => {
  const marker = window.BM.marker(convertStringToLatLng(options.mapPoints), {
    icon: window.BM.divIcon({ html: initSiteIcon(options), iconSize: null, className: '' })
  }).addTo(layer);
  marker.stationProps = { sitesId: options.sitesId, alarmLevel: options.alarmLevel, zoom: options.mapLevel };
  return marker;
};
